package cn.edu.ctbu.controller.admin;

import cn.edu.ctbu.DTO.EmpDTO;
import cn.edu.ctbu.DTO.EmpPageDTO;
import cn.edu.ctbu.VO.EmpLoginVO;
import cn.edu.ctbu.entity.Employee;
import cn.edu.ctbu.result.PageResult;
import cn.edu.ctbu.result.Result;
import cn.edu.ctbu.service.IEmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/admin/employee")
@Api(tags = "员工相关接口")
public class EmployeeController {
    @Autowired
    private IEmployeeService iEmployeeService;

    @ApiOperation("员工登录")
    @PostMapping("/login")
    public Result<EmpLoginVO> Login(@RequestBody EmpDTO empDTO){

    EmpLoginVO emp=iEmployeeService.login(empDTO);
    return Result.success(emp);

    }

    /**
     * 获得员工列表
     */
    @ApiOperation("分页查询员工")
    @GetMapping
    public Result<PageResult> getList(EmpPageDTO pageDTO){
        PageResult list=iEmployeeService.getList(pageDTO);

        return Result.success(list);
    }

    /**
     * 启用禁用员工账号
     */
    @ApiOperation("启动禁用员工")
    @GetMapping("/status")
    public Result EmpStatus(Long id){
        iEmployeeService.Empstatus(id);
        return Result.success();
    }

    /**
     * 添加新员工
     */
    @ApiOperation("添加员工")
    @PostMapping("/add")
    public Result addEmp(@RequestBody Employee employee){
        iEmployeeService.addEmp(employee);
        return Result.success();
    }

    /**
     * 修改员工
     */
    @ApiOperation("修改员工")
    @PutMapping("/put")
    public Result putEmp(@RequestBody Employee employee){
        iEmployeeService.putEmp(employee);
        return Result.success();
    }
}
